#ifndef CONTROL_H
#define CONTROL_H
#include "systemHead.h"


class Dot:public QWidget
{
    Q_OBJECT
public:
    Dot(QWidget *parent = nullptr);
    virtual ~Dot();
signals:
    void moveDot(int x);
    void EndDot(int x);
private:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
private:
    QPoint          _mousePos;
};


class BarAndDot:public QWidget
{
    Q_OBJECT
public:
    BarAndDot(QWidget *parent = nullptr);
    virtual ~BarAndDot();
signals:
    void adjustProgress(double rotia);//参数是占总进度的比例 给ffmpeg的调整信号
    void updateTimeStamp(double rotia);//更新进度读条的左右时间戳
private slots:
    void acceptMoveDot(int x);
    void acceptEndDot(int x);
    void upDateProgress();//定时器根据ffmpeg的进度更新进度条，并发送updateTimeStamp
private:
    void paintEvent(QPaintEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
private:
    Dot         *_dot;
    int         _moveX = 0;
    double      _rotia = 0;
    QTimer      *_ti = nullptr;
};


class Progress:public QWidget
{
    Q_OBJECT
public:
    Progress(QWidget *parent = nullptr);
    virtual ~Progress();
    void SetDuration(int64_t time);//设置总时长
private slots:
    void acceptUpdateTimeStamp(double rotia);
signals:
    void adjustProgress(double rotia);//参数是占总进度的比例
private:
    void loadWidget();
private:
    QLabel      *_labelLeft, *_labelRight;
    BarAndDot         *_barDot;
    int64_t            _sumTime = 0;//单位毫秒
};




class Control:public QWidget
{
    Q_OBJECT
public:
    Control(QWidget *parent = nullptr);

    virtual ~Control();
    static bool                 LastStartFlag;//用于记录按下调整进度前的播放状态
signals:
    void adjustProgress(double);
private slots:

    void updatePlayStatue();
    void reset();
    void acceptDuration(double time)
    {
        auto temp = static_cast<int>(time);
        _progress->SetDuration(temp);
    }
private:
    void paintEvent(QPaintEvent *event) override;
    void loadWidget();
private:
    QPushButton         *_button;
    Progress            *_progress;
};

#endif // CONTROL_H
